/*
 * @Author: youngqj youngqj@126.com
 * @Date: 2024-10-21 19:36:49
 * @LastEditors: youngqj youngqj@126.com
 * @LastEditTime: 2024-11-01 23:11:43
 * @FilePath: /go/mallSystem/routes/url.go
 * @Description:
 *
 * Copyright © Zhejiang Xiaoqu Information Technology Co., Ltd, All Rights Reserved.
 */
package routes

import (
	"fmt"
	"path/filepath"
	"xiaoquio/web/core/utils"

	"github.com/gin-gonic/gin"
)

// InitRoutes 初始化路由
func SetupDefaultRoutes(r *gin.Engine) {

	absPath, _ := filepath.Abs("./../template/*")

	r.LoadHTMLGlob(absPath)
	systemInfo := utils.GetDiskUsage()
	memInfo := utils.GetMemoryUsage()

	r.GET("/", func(c *gin.Context) {
		///elapsedTime, _ := c.Get("elapsedTime")
		elapsedTime, exists := c.Get("elapsedTime")
		if !exists {
			fmt.Println("elapsedTime not found in context") // 检查是否获取到
		} else {
			fmt.Println("Elapsed time in route:", elapsedTime) // 输出获取的时间
		}

		// 渲染模板，并将处理时间传递过去
		c.HTML(200, "index.html", gin.H{
			"title":       "页面标题222",
			"elapsedTime": elapsedTime,
			"sysInfo":     systemInfo,
			"memInfo":     memInfo,
		})

	})
	r.GET("/test", func(ctx *gin.Context) {
		utils.RetSucess(ctx, "test")
	})

}
